# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=dbus-python
pkgname=(dbus-python dbus-python-docs)
pkgver=1.3.2
pkgrel=2
pkgdesc='Python bindings for D-Bus'
arch=('loong64' 'x86_64')
url='https://www.freedesktop.org/wiki/Software/dbus/'
license=('MIT')
depends=('dbus' 'glib2' 'glibc' 'python')
makedepends=('meson' 'python-sphinx' 'python-sphinx_rtd_theme')
optdepends=('python-gobject: D-Bus services via PyGI')
source=("https://dbus.freedesktop.org/releases/$pkgname/$pkgname-$pkgver.tar.gz"{,.asc})
sha256sums=('ad67819308618b5069537be237f8e68ca1c7fcc95ee4a121fe6845b1418248f8'
            'SKIP')
validpgpkeys=('DA98F25C0871C49A59EAFF2C4DE8FF2A63C7CC90')

build() {
  arch-meson $pkgname-$pkgver build -D doc=true
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

package_dbus-python() {
  conflicts=('python-dbus' 'python-dbus-common')
  provides=("python-dbus=$pkgver" "python-dbus-common=$pkgver")
  replaces=('python-dbus' 'python-dbus-common')

  meson install -C build --destdir "$pkgdir"

  # Compile Python bytecode
  python -m compileall -d /usr/lib "$pkgdir/usr/lib"
  python -O -m compileall -d /usr/lib "$pkgdir/usr/lib"

  # Install egg-info and license
  install -Dm644 -t "$pkgdir/usr/lib/python3.11/site-packages/dbus_python-$pkgver.egg-info/" "$srcdir"/$pkgname-$pkgver/dbus_python.egg-info/*
  install -Dm644 "$pkgbase-$pkgver/COPYING" "$pkgdir/usr/share/licenses/$pkgname/COPYING"

  # Split documentation
  mkdir -p doc/usr/share
  mv {"$pkgdir",doc}/usr/share/doc
}

package_dbus-python-docs() {
  pkgdesc="Developer documentation for dbus-python"
  depends=()
  optdepends=()

  mv doc/* "$pkgdir"
  rm -r "$pkgdir/usr/share/doc/$pkgbase/html/.doctrees"
  install -Dm644 "$pkgbase-$pkgver/COPYING" "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}
